package com.liuxvru.project.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liuxvru.common.utils.SecurityUtils;
import com.liuxvru.project.domain.ProjectAnnouncement;
import com.liuxvru.project.mapper.ProjectAnnouncementMapper;
import com.liuxvru.project.service.IProjectAnnouncementService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 项目公告Service业务层处理
 *
 * @author liuxvru
 * @date 2024-11-22
 */
@Service
public class ProjectAnnouncementServiceImpl extends ServiceImpl<ProjectAnnouncementMapper, ProjectAnnouncement> implements IProjectAnnouncementService {


    /**
     * 查询项目公告列表
     *
     * @param projectAnnouncement 项目公告
     * @return 项目公告
     */
    @Override
    public List<ProjectAnnouncement> selectProjectAnnouncementList(ProjectAnnouncement projectAnnouncement) {
        return baseMapper.selectProjectAnnouncementList(projectAnnouncement);
    }

    @Override
    public List<ProjectAnnouncement> listByProjectId(Long projectId, ProjectAnnouncement projectAnnouncement) {
        projectAnnouncement.setProjectId(projectId);
        return baseMapper.selectProjectAnnouncementList(projectAnnouncement);
    }

    @Override
    public int add(Long projectId, ProjectAnnouncement projectAnnouncement) {
        Long userId = SecurityUtils.getUserId();
        projectAnnouncement.setProjectId(projectId);
        projectAnnouncement.setUpdatedBy(userId);
        projectAnnouncement.setCreatedBy(userId);
        projectAnnouncement.setReviewStatus("1");//待审核
        return baseMapper.insert(projectAnnouncement);
    }

    @Override
    public int edit(ProjectAnnouncement projectAnnouncement) {
        projectAnnouncement.setUpdatedBy(SecurityUtils.getUserId());

        return baseMapper.updateById(projectAnnouncement);
    }
}
